<template>
  <div
    class="singleSmallCard"
    :class="{
      singleSmallCardOutline: !this.enableView,
    }"
    @click="clickBtn()"
  >
    <div class="titleContainer">
      <div class="topTitleContainer">
        <div class="title">{{ this.title }}</div>
        <img
          class="tipImg"
          :src="getTipImg"
          v-show="showTipImg"
          @click="clickTipBtn"
          @click.stop="clickStopFather"
        />
      </div>
      <div class="state" v-show="isOn">
        {{ this.getSubtitle }}
      </div>
    </div>
    <img class="img" :src="getButtonImage" />
    <slot></slot>
  </div>
</template>
<script>
export default {
  props: {
    enableViewProp: {
      type: Boolean,
      default: false,
    },
    isOnProp: {
      type: Boolean,
      default: false,
    },
    titleProp: {
      type: String,
      default: "按钮",
    },
    imgStrProp: {
      type: String,
      default: null,
    },
    showTipImgPro: {
      type: Boolean,
      default: false,
    },
    darkModePro: {
      type: String,
      default: "light",
    },
    subtitleProp: {
      type: String,
      default: null,
    },
  },
  data() {
    return {
      enableView: false, //按钮是否可用
      isOn: false, //按钮是否开启
      title: "", //按钮标题
      subtitle: null, //副标题（按钮状态说明）
      imgStr: null, //按钮图标
      showTipImg: false,
      darkMode: "light",
    };
  },
  mounted() {
    this.enableView = this.enableViewProp;
    this.isOn = this.isOnProp;
    this.title = this.titleProp;
    this.imgStr = this.imgStrProp;
    this.showTipImg = this.showTipImgPro;
    this.darkMode = this.darkModePro;
    this.subtitle = this.subtitleProp;
  },

  watch: {
    enableViewProp(newVal) {
      this.enableView = newVal;
    },
    isOnProp(newVal) {
      this.isOn = newVal;
    },
    imgStrProp(newVal) {
      this.imgStr = newVal;
    },
    showTipImgPro(newVal) {
      this.showTipImg = newVal;
    },
    darkModePro(newVal) {
      this.darkMode = newVal;
    },
    subtitleProp(newVal) {
      this.subtitle = newVal;
    },
  },
  computed: {
    getSubtitle() {
      if (this.subtitle == null) {
        return this.$i18n.t("btnTitle.on");
      } else {
        return this.subtitle;
      }
    },
    getButtonImage: function () {
      return this.imgStr;
    },
    getTipImg() {
      return this.darkMode === "light"
        ? require("../../assets/img/light/ic_warmwind_show_tip.png")
        : require("../../assets/img/dark/ic_warmwind_show_tip_dark.png");
    },
  },
  methods: {
    clickBtn() {
      // console.log("点击父级");
      this.$emit("click");
    },
    clickTipBtn() {
      // console.log("点击子级");
      this.$emit("clickTip");
    },
    clickStopFather() {
      // console.log("阻止点击父级");
    },
  },
};
</script>
<style scoped>
.singleSmallCard {
  flex: 1;
  display: flex;
  height: 100%;
  border-radius: 16px;
  background-color: var(--current-card-background-color);
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  /* background: #000; */
}

.singleSmallCard:active {
  opacity: 0.3;
}

.singleSmallCard .img {
  width: 24px;
  height: 24px;
  margin-right: 16px;
}

.singleSmallCard .titleContainer {
  margin-left: 16px;
  flex-direction: column;
}

.singleSmallCard .titleContainer .state {
  font-size: 12px;
  color: var(--current-second-title-color);
  margin-top: 2px;
}

.singleSmallCard .titleContainer .topTitleContainer {
  display: flex;
  flex-direction: row;
  align-items: center;
}

.singleSmallCard .titleContainer .topTitleContainer .title {
  font-size: 16px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  /* background: #ff0000; */
  color: var(--current-primary-color);
}

.singleSmallCard .titleContainer .topTitleContainer .tipImg {
  width: 16px;
  height: 16px;
  margin-left: 4px;
}

.singleSmallCardOutline {
  opacity: 0.4;
}
</style>
